package dukeAll;


import java.util.LinkedList;
import java.util.Queue;

public class Tourney {
  public String winner(String[] bracket, String results) {

    Queue<String> q = new LinkedList<String>();
    
    for (String str:bracket) {
      q.offer(str);
      }
    int i = 0;
    while(i < results.length()) {
      
      String a = q.poll();
      String b = q.poll();
      
      if (a == "bye") {
        q.offer(b);
        continue;
      }
      if (b == "bye") {
        q.offer(a);
        continue;     
      }
      
      {
      if (results.charAt(i) == 'H')
        q.offer(a);
      if (results.charAt(i) == 'L')
        q.offer(b);
       
      i++; }
     
     }
     return q.peek();
  }
}